package com.s3.khospitalds.controller;

import com.s3.khospitalds.common.R;
import com.s3.khospitalds.entity.Drugs;
import com.s3.khospitalds.service.impl.DrugsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: xw
 * @CreateTime: 2025/2/26
 * @Description: 药品信息表
 * @Version: 1.0
 */
@RestController
@CrossOrigin(origins = "*")
public class DrugController {
    @Autowired
    DrugsServiceImpl drugsService;

    @GetMapping("/getDrugsByType") //中药信息
    public R getDrugsByType(){
        return new R().addData("list",drugsService.getDrugs());
    }
    @GetMapping("/getDrugsByTypeW") //西药信息
    public R getDrugsByTypeW(){
        return new R().addData("list",drugsService.getDrugsW());
    }
    @GetMapping("/getDrugsByTypeLike/{type}")
    public R getDrugsByTypeLike(@PathVariable("type") String type){
        return new R().addData("list",drugsService.getDrugsByTypeLike(type));
    }
    @PostMapping("/insertDrugs")
    public R insertDrugs(@RequestBody Drugs drugs){
        return new R().addData("list",drugsService.insertDrugs(drugs));
    }
    @GetMapping("/getDrugsByQuantity")
    public R getDrugsByQuantity(){
        return new R().addData("list",drugsService.getDrugsByQuantity());
    }
    @GetMapping("/getDrugsByTypeLikeW/{type}")
    public R getDrugsByTypeLikeW(@PathVariable("type") String type){
        return new R().addData("list",drugsService.getDrugsByTypeLikeW(type));
    }

    @GetMapping("/getDrugsByDrugNameLike/{drugname}")
    public R getDrugsByDrugNameLike(@PathVariable("drugname") String drugname){
        return new R().addData("list",drugsService.getDrugsByDrugNameLike(drugname));
    }
    @PostMapping("/insertDrugsW")
    public R insertDrugsW(@RequestBody Drugs drugs){
        return new R().addData("list",drugsService.insertDrugsW(drugs));
    }
    @GetMapping("/getDrugsByQuantityW")
    public R getDrugsByQuantityW(){
        return new R().addData("list",drugsService.getDrugsByQuantityW());
    }

    @PostMapping("/updateDrugsQuantity")
    public R updateDrugsQuantity(@RequestBody Drugs drugs){
        return new R().addData("list",drugsService.updateDrugsQuantity(drugs));
    }

    @PostMapping("/updateDrugs")
    public R updateDrugs(@RequestBody Drugs drugs){
        return new R().addData("list",drugsService.updateDrugs(drugs.getDrugname(), (int) drugs.getQuantity()));
    }
    //修改中药
    @PostMapping("/updateDrugsW")
    public R updateDrugsW(@RequestBody Drugs drugs){
        return new R().addData("list",drugsService.updateDrugsW(drugs.getDrugname(), (int) drugs.getQuantity()));
    }
}
